import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/manager/xindong_yinsi_singleton.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';

class XinDongAgreementView extends StatelessWidget {
  const XinDongAgreementView({super.key});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => XinDongYinSiSingleton.to.changePrivacy(),
      behavior: HitTestBehavior.opaque,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          GetBuilder<XinDongYinSiSingleton>(
            builder: (controller) {
              return Checkbox(
                value: controller.agreement.agreePrivacy,
                materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                onChanged: (value) => controller.changePrivacy(),
              );
            },
          ),
          Flexible(
            child: Text.rich(
              TextSpan(text: "阅读并同意", children: [
                TextSpan(
                  text: "《隐私政策》",
                  style: const TextStyle(color: DZColors.mainBlueColor),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      XinDongPageSingleton.instance.jumpToWebYeMian(title: "隐私政策", url: XinDongNetworking.instance.privacyUrl);
                    },
                ),
                TextSpan(
                  text: "《用户协议》",
                  style: const TextStyle(color: DZColors.mainBlueColor),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      XinDongPageSingleton.instance.jumpToWebYeMian(title: "用户协议", url: XinDongNetworking.instance.agreementUrl);
                    },
                ),
              ]),
              style: const TextStyle(fontSize: 13, color: DZColors.contentColor),
            ),
          ),
        ],
      ),
    );
  }
}
